/**
 * 解析所有模块下国际化资源文件装配到主资源文件中
 */
import config from '@/common/app/config.js'
// import VueI18n from 'vue-i18n'

const langKeys = [];
for (let key in config.LANGUAGE_CONFIG) {
  langKeys.push(key);
}
// 公共语种配置在/common/lang目录下
const commonContext = require.context('@/common/lang', true, /\.js$/);
let commonLanguage = {};
commonContext.keys().forEach(key => {
  const tempKey = key.split('/');
  const langKey = tempKey[tempKey.length - 1].split('.js')[0];
  if (langKeys.indexOf(langKey) !== -1) {
    commonLanguage[langKey] = Object.assign((commonLanguage[langKey] || {}), commonContext(key).default);
  }
});
const moduleContext = require.context('@/modules', true, /\/lang\/.*\.js$/);
let moduleLanguage = {};
moduleContext.keys().forEach(key => {
  const tempKey = key.split('/');
  const langKey = tempKey[tempKey.length - 1].split('.js')[0];
  if (langKeys.indexOf(langKey) !== -1) {
    const elLang = config.LANGUAGE_CONFIG[langKey].elLang;
    moduleLanguage[langKey] = {
      ...moduleLanguage[langKey],
      ...moduleContext(key).default,
      ...require(`element-ui/lib/locale/lang/${elLang}`).default
    }
  }
});
let messages = {};
langKeys.forEach((item) => {
  messages[item] = Object.assign((commonLanguage[item] || {}), (moduleLanguage[item] || {}));
})

// Vue.use(VueI18n);

// const i18n = new VueI18n({
//   locale: DEFAULT_LOCALE,
//   messages
// });

// /**
//  * 设置i18n的语种
//  * @param newLocale
//  */
// i18n.setLocale = function (newLocale) {
//   i18n.locale = newLocale;
// };

export default messages;
